ArcPadScripting
Project Example

 

Description

ProjectLLToMap projects WGS 1984 latitude/longitude coordinates to map projection coordinates.

VBScript Code

Copy Code
Sub ProjectLLToMap (dblLat, dblLon)
      'Create a point object
      Dim pPt
      Set pPt = Application.CreateAppObject ("Point")
      
      'Create a WGS 1984 Lat/Lon CoordSys object
      'Assumes the file WGS 1984.prj exists in the My Documents folder
      Dim pLatLonCS 
      Set pLatLonCS = Application.CreateAppObject ("CoordSys")
      pLatLonCS.Import Application.System.Properties("PersonalFolder") & "\WGS 1984.prj" 
      
      'Set the point object's coordsys to Lat/Lon WGS 1984
      Set pPt.CoordinateSystem = pLatLonCS
      
      'Assign the lat/lon values to the point object
      pPt.X = dblLon
      pPt.Y = dblLat
      
      'Project the point to the map's coordinate system
      Dim pProj
      Set pProj = Map.CoordinateSystem.Project(pPt)
      
      'Display the projected coordinates
      MsgBox "X: " & pProj.X & vbCr & "Y: " & pProj.y, vbInformation, "Projected coordinates"
      
      'Clean up
      Set pPt = Nothing
      Set pLatLonCS = Nothing
      Set pProj = Nothing
End Sub
Sub ProjectMapToLL (dblX, dblY)
      'Create a Point object (which inherits the map's coordsys)
      Dim pPt
      Set pPt = Application.CreateAppObject ("Point")
      
      'Assign the X and Y values to the point object
      pPt.X = dblX
      pPt.Y = dblY
      'Create a WGS 1984 lat/lon CoordSys object
      'Assumes the file WGS 1984.prj exists in the My Documents folder
      Dim pLatLonCS 
      Set pLatLonCS = Application.CreateAppObject ("CoordSys")
      pLatLonCS.Import Application.System.Properties("PersonalFolder") & "\WGS 1984.prj" 
      
      'Unproject the point to WGS 1984 Lat/Lon
      Dim pUnproj
      Set pUnproj = pLatLonCS.Project (pPt)
      
      'Display the unprojected coordinates
      MsgBox "X: " & pUnproj.X & vbCr & "Y: " & pUnproj.Y, vbInformation, "Projected coordinates"
      
      'Clean up
      Set pPt = Nothing
      Set pLatLonCS = Nothing
      Set pUnProj = Nothing
End Sub